package cn.wolfcode.trip.base.util;

import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

public abstract class UserContext {
    //定义两个常量,代表着用户和权限表达式
    public static final String USER_IN_SESSION="USER_IN_SESSION";
    //获取session的方法
    private static HttpSession getSession(){
        return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }

    //用户的getset方法
    public static User getCurrentUser(){
        return  (User)getSession().getAttribute("USER_IN_SESSION");
    }
    //用户的getset方法
    public static void setCurrentUser(User e){
        getSession().setAttribute("USER_IN_SESSION",e);
    }

}
